﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;
using EnvDTE80;
using Common.Configs;

namespace BovespaNamingRules
{
    public sealed class Rule_BovespaAvoidLongMethodNames : BaseAddIn.Rules.BaseRuleAddIn
    {
        #region Fields

        private int _lengthMethod;

        #endregion

        #region Constructor

        public Rule_BovespaAvoidLongMethodNames() :
            base("BovespaAvoidLongMethodNames", "BovespaNamingRules.BovespaNamingRules", typeof(Rule_BovespaAvoidLongMethodNames).Assembly)
        {
            this._lengthMethod = Settings.LengthMethod;
        }

        #endregion

        #region Protected Override Methods

        protected sealed override void Check(CodeFunction funcao, CodeNamespace namespaceElement, CodeClass2 classe)
        {
            if (funcao.FunctionKind == vsCMFunction.vsCMFunctionFunction
                && funcao.Name.Length > _lengthMethod)
            {
                GeraProblemaAddIn(funcao.StartPoint.Parent.Parent.FullName,
                                  funcao.StartPoint.Line,
                                  funcao.StartPoint.DisplayColumn,
                                  "BovespaAvoidLongMethodNamesResolution",
                                  classe.Name,
                                  funcao.Name,
                                  namespaceElement.Name,
                                  Settings.LengthMethod.ToString());
            }
        }

        #endregion
    }
}
